package com.xuyuan.protocol;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class MyCustomProtocolClient {

    @Qualifier("cutomProtocolRestTemplate")
    @Autowired
    private RestTemplate restTemplate;

    public MyCustomProtocol sendCustomProtocol(String url, MyCustomProtocol request) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.parseMediaType("application/x-custom-protocol"));
        HttpEntity<MyCustomProtocol> entity = new HttpEntity<>(request, headers);
        return restTemplate.postForObject(url, entity, MyCustomProtocol.class);
    }
}
